<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">摄像头编码</label>
        <el-input v-model="query.cameraCode" clearable placeholder="摄像头编码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">摄像头名称</label>
        <el-input v-model="query.cameraName" clearable placeholder="摄像头名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="1000px">
        <el-form ref="form" :model="form" inline :rules="rules" size="small" label-width="130px">
          <el-form-item label="摄像头编码">
            <el-input v-model="form.cameraCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="摄像头类型">
            <el-input v-model="form.cameraType" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="设备名称">
            <el-input v-model="form.deviceName" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="设备IP">
            <el-input v-model="form.deviceIp" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="摄像头名称">
            <el-input v-model="form.cameraName" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="设备编码">
            <el-input v-model="form.deviceCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="RTSP视频流">
            <el-input v-model="form.rtspVideoStream" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="接口请求地址">
            <el-input v-model="form.interfaceIp" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="视频播放地址">
            <el-input v-model="form.videoPlayingUrl" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="经度">
            <el-input v-model="form.longitude" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="纬度">
            <el-input v-model="form.latitude" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="端口号">
            <el-input v-model="form.port" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="登录用户">
            <el-input v-model="form.loginUser" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="登录密码">
            <el-input v-model="form.password" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="所属图层">
            <el-input v-model="form.mapId" style="width: 250px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="cameraCode" label="摄像头编码" />
        <el-table-column prop="cameraName" label="摄像头名称" />
        <el-table-column prop="deviceCode" label="设备编码" />
        <el-table-column prop="videoPlayingUrl" label="视频地址" />
        <el-table-column label="播放">
          <template slot-scope="scope">
            <el-button v-if="scope.row.cameraType==='1'" @click="getView(scope.row)">预览</el-button>
            <el-button v-if="scope.row.cameraType==='0'" @click="getHKView(scope.row)">预览</el-button>

          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','video:edit','video:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <myview ref="myview" />
      <Preview ref="preview" />

    </div>

  </div>
</template>

<script>
import myview from './myview'
import crudVideo from '@/api/video'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import Preview from './preview'

const defaultForm = { id: null, cameraType: null, cameraCode: null, deviceName: null, deviceIp: null, cameraName: null, deviceCode: null, rtspVideoStream: null, interfaceIp: null, videoPlayingUrl: null, longitude: null, latitude: null, port: null, loginUser: null, password: null, mapId: null }
export default {
  name: 'Video',
  components: { Preview, pagination, myview, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'video', url: 'api/video', idField: 'id', sort: 'id,desc', crudMethod: { ...crudVideo }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'video:add'],
        edit: ['admin', 'video:edit'],
        del: ['admin', 'video:del']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'cameraCode', display_name: '摄像头编码' },
        { key: 'cameraName', display_name: '摄像头名称' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    getView(data) {
      console.log(data)
      data = data.videoPlayingUrl
      this.$refs.myview.url = data
      this.$refs.myview.loadCamera()
      this.$refs.myview.dialog = true
    },
    getHKView(data) {
      // console.log('hk')
      this.$refs.preview.show(data)
    }
  }
}
</script>

<style scoped>

</style>
